package com.windaka.elements.config;


import com.windaka.elements.websocket.handler.LayoutWebSocketHandler;
import com.windaka.elements.websocket.interceptor.WebSocketInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * 配置WebSocketServer
 * @author song
 * @date 10:17 2022/8/22
**/
@EnableWebSocket
@Configuration
@RequiredArgsConstructor
public class WebSocketServerConfig implements WebSocketConfigurer {

    private final LayoutWebSocketHandler layoutWebSocketHandler;

    private final WebSocketInterceptor webSocketInterceptor;

    /**
     * 配置拦截器等
     * @author song
     * @date 11:19 2022/8/22
    **/
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        webSocketHandlerRegistry
                .addHandler(layoutWebSocketHandler, "/dataServer")
                .setAllowedOrigins("*")
                .addInterceptors(webSocketInterceptor);
    }

}
